import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from '@/views/Login/Login.vue'
import Reg from '@/views/Reg/Reg.vue'
import Main from '@/views/Main/Main.vue'

import Home from "@/views/Menus/Home/Home.vue"
import UserInfo from '@/views/Menus/User/UserInfo.vue'
import UserAvatar from '@/views/Menus/User/UserAvatar.vue'
import UserPwd from '@/views/Menus/User/UserPwd.vue'
import ArtCate from '@/views/Menus/Article/ArtCate.vue'

Vue.use(VueRouter)

// 把下面的代码粘贴到路由模块中对应的位置，即可防止路由报错的问题
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
  // 把错误捕获
}

//路由规则
const routes = [ 
  // 登录
  {
    path: '/login',
    component: Login,
    name:'login'
  },
  // 注册
  {
    path: '/reg',
    component: Reg,
    name:'reg'
  },
  //后台主页的路由规则
  {
    path:'/',
    component:Main,//首页
    redirect:'/home',
    name:'main',
    // 二级路由的设置
    children:[
      // 首页里面的主页
      {path:'home',name:'home',component:Home},
      // 
      {path:'user-info',name:'userInfo',component:UserInfo},//修改信息
      {path:'user-avatar',name:'UserAvatar',component:UserAvatar},//修改头像
      {path:'user-pwd',name:'UserPwd',component:UserPwd},//修改密码
      {path:'art-cate',name:'ArtCate',component:ArtCate},//
    ]
  },


]

const router = new VueRouter({
  routes
})

export default router
